package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.SysDeptPositions;
import cn.stylefeng.guns.sys.modular.system.mapper.SysDeptPositionsMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.SysDeptPositionsParam;
import cn.stylefeng.guns.sys.modular.system.model.params.SysPositionsParam;
import cn.stylefeng.guns.sys.modular.system.model.result.SysDeptPositionsResult;
import  cn.stylefeng.guns.sys.modular.system.service.SysDeptPositionsService;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.jws.soap.SOAPBinding;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 部门岗位关系表 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-01-10
 */
@Service
public class SysDeptPositionsServiceImpl extends ServiceImpl<SysDeptPositionsMapper, SysDeptPositions> implements SysDeptPositionsService {

    @Autowired
    private UserService userService;

    @Override
    public void add(SysDeptPositionsParam param){

        SysDeptPositions entity = getEntity(param);
        entity.setDeliverId(userService.getDeliverId());
        this.save(entity);
    }




    @Override
    public void delete(SysDeptPositionsParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(SysDeptPositionsParam param){
        SysDeptPositions oldEntity = getOldEntity(param);
        SysDeptPositions newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public SysDeptPositionsResult findBySpec(SysDeptPositionsParam param){
        return null;
    }

    @Override
    public List<SysDeptPositionsResult> findListBySpec(SysDeptPositionsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(SysDeptPositionsParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(SysDeptPositionsParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private SysDeptPositions getOldEntity(SysDeptPositionsParam param) {
        return this.getById(getKey(param));
    }

    private SysDeptPositions getEntity(SysDeptPositionsParam param) {
        SysDeptPositions entity = new SysDeptPositions();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
    public Page<Map<String, Object>> list(String condition, Long deptId, Long DeliverId) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.list(page, condition, deptId,DeliverId);
    }

}
